<?php

namespace catchAdmin\basics\controller;

use catchAdmin\basics\model\NewsWebsite as newsWebsiteModel;
use catcher\base\CatchRequest as Request;
use catcher\CatchAdmin;
use catcher\CatchAuth;
use catcher\CatchResponse;

class NewsWebsite extends CatchAdmin
{
    public function __construct(newsWebsiteModel $newsWebsiteModel)
    {
        $this->newsWebsiteModel = $newsWebsiteModel;
    }

    //列表
    public function index(CatchAuth $auth, Request $request)
    {
        $user = $auth->user();
        return CatchResponse::paginate($this->newsWebsiteModel->getList($user['tenant_id']));
    }

    //禁用or启用
    public function disOrEnable($id, CatchAuth $auth, Request $request)
    {
        $model = $this->newsWebsiteModel->findBy($id);
        $model->status = $model->status == '启用' ? '禁用' : '启用';
        return CatchResponse::success($model->save());
    }
}